package com.zjy.system.service.impl;

import com.zjy.system.domain.Role;
import com.zjy.system.mapper.MenuMapper;
import com.zjy.system.mapper.PermissionMapper;
import com.zjy.system.mapper.RoleMapper;
import com.zjy.system.service.RoleService;
import com.zjy.basic.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 业务实现类：
 */
@Service
public class RoleServiceImpl extends BaseServiceImpl<Role> implements RoleService {

    @Autowired
    private RoleMapper roleMapper;
    @Autowired
    private MenuMapper menuMapper;
    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    @Transactional
    public void add(Role role) {
        //删除此role对应的所有menu编辑的时候必要
//        menuMapper.deleteByRoleId();
        roleMapper.add(role);
        //保存t_role_menu
        roleMapper.addRoleMenu(role.getId(),role.getMenus());
        //删除此role对应的所有permission 编辑的时候必要
//        permissionMapper.deleteByRoleId();

        //保存t_role_permission
        roleMapper.addRolePermission(role.getId(),role.getPermissions());
    }

//    @Override
//    @Transactional
//    public void update(Role role) {
//        //删除此role对应的所有menu编辑的时候必要
////        menuMapper.deleteByRoleId();
//        roleMapper.update(role);
//        //保存t_role_menu
//        roleMapper.updateMenu(role.getId(),role.getMenus());
//        //删除此role对应的所有permission 编辑的时候必要
////        permissionMapper.deleteByRoleId();
//
//        //保存t_role_permission
//        roleMapper.updateRolePermission(role.getId(),role.getPermissions());
//    }
}
